import Vue from 'vue';
import UniRouteGuards from '@/common/uniapp-route-guards';
Vue.use(UniRouteGuards);
const install = (Vue, vm) => {
	const guard = new UniRouteGuards();
	/**
	 * 自定义路由拦截白名单
	 */
	const WHILE_LIST = ['/src/pages/home', '/src/pages/log'];
	/**
	 * 全局前置守卫
	 */
	guard.beforeEach((to, from, next) => {
        console.log("to: ",to);
		if (WHILE_LIST.includes(from.url)) {
			return next(to.url);
		}
		const token = uni.getStorageSync('token');
		// if (!token) {
		// 	vm.$u.vuex('vuex_login', 1)
		// } else {
		// 	vm.$u.vuex('vuex_login', 0)
		// 	next();
		// }
        next();
	});

	// 拦截 调用 uni.switchTab 页面C并跳转到 页面D
	guard.beforeEach((to, from, next) => {
		if (to.action === 'switchTab' && to.url === '/src/pages/c') {
			return next({
				url: '/src/pages/d',
				action: 'navigateTo'
			});
		}
		next();
	});
	/**
	 * 全局后置后卫
	 */
	guard.afterEach((to, from) => {});

}
export default {
	install
}
